Can't rename a file if the target exists on Win32. First rename the target
authorTor Lillqvist <tml@novell.com>
Sun, 6 Nov 2005 06:27:01 +0000 (06:27 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Sun, 6 Nov 2005 06:27:01 +0000 (06:27 +0000)
2005-11-06  Tor Lillqvist  <tml@novell.com>

* gtk/updateiconcache.c (build_cache): Can't rename a file if the
target exists on Win32. First rename the target temporarily, then
if the renaming of the source to target fails, restore the
original name for the target.

* gtk/Makefile.am: Use EXEEXT in the dependency on gtk-update-icon-cache.

ChangeLog
ChangeLog.pre-2-10
gtk/Makefile.am
gtk/updateiconcache.c

index d885a786128a1c77d9eea9331a4581d6e260f94b..85434ceb4267286a0414deb1fcc44376ecff5369 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-11-06  Tor Lillqvist  <tml@novell.com>
+
+       * gtk/updateiconcache.c (build_cache): Can't rename a file if the
+       target exists on Win32. First rename the target temporarily, then
+       if the renaming of the source to target fails, restore the
+       original name for the target.
+
+       * gtk/Makefile.am: Use EXEEXT in the dependency on gtk-update-icon-cache.
+
 2005-11-06  Tor Lillqvist  <tml@novell.com>
 
        (pixbuf_to_hbitmaps_alpha_winxp): Use an 1-bit mask bitmap,
index d885a786128a1c77d9eea9331a4581d6e260f94b..85434ceb4267286a0414deb1fcc44376ecff5369 100644 (file)
@@ -1,3 +1,12 @@
+2005-11-06  Tor Lillqvist  <tml@novell.com>
+
+       * gtk/updateiconcache.c (build_cache): Can't rename a file if the
+       target exists on Win32. First rename the target temporarily, then
+       if the renaming of the source to target fails, restore the
+       original name for the target.
+
+       * gtk/Makefile.am: Use EXEEXT in the dependency on gtk-update-icon-cache.
+
 2005-11-06  Tor Lillqvist  <tml@novell.com>
 
        (pixbuf_to_hbitmaps_alpha_winxp): Use an 1-bit mask bitmap,
index c567ae9550da228b3bf02c49ac55fe79d491a978..74e555cec8cf930540210ba0fab1e6935773f8c4 100644 (file)
@@ -953,7 +953,7 @@ STOCK_ICONS = \
 
 icons:
        for i in 16 24; do                                              \
-          (cd stock-icons/$$i                                          \
+          (cd stock-icons/$$i                                          \
           $(LN_S) gtk-go-forward-ltr.png gtk-go-back-rtl.png           \
           $(LN_S) gtk-go-back-ltr.png gtk-go-forward-rtl.png           \
           $(LN_S) gtk-goto-first-ltr.png gtk-goto-last-rtl.png         \
@@ -966,7 +966,7 @@ icons:
           cd ../..)                                                    \
        done
 
-gtkbuiltincache.h: @REBUILD@ gtk-update-icon-cache icons
+gtkbuiltincache.h: @REBUILD@ gtk-update-icon-cache$(EXEEXT) icons
        ./gtk-update-icon-cache --force --ignore-theme-index    \
           --source builtin_icons stock-icons > gtkbuiltincache.h
 
index 31906f9524b5d2aefd8eb05841525837b21aa888..9453e73974b16cdad2df0d8b2800f52a4f1ff55f 100644 (file)
@@ -1143,6 +1143,9 @@ void
 build_cache (const gchar *path)
 {
   gchar *cache_path, *tmp_cache_path;
+#ifdef G_OS_WIN32
+  gchar *bak_cache_path = NULL;
+#endif
   GHashTable *files;
   gboolean retval;
   FILE *cache;
@@ -1188,11 +1191,42 @@ build_cache (const gchar *path)
 
   cache_path = g_build_filename (path, CACHE_NAME, NULL);
 
+#ifdef G_OS_WIN32
+  if (g_file_test (cache_path, G_FILE_TEST_EXISTS))
+    {
+      bak_cache_path = g_strconcat (cache_path, ".bak", NULL);
+      g_unlink (bak_cache_path);
+      if (g_rename (cache_path, bak_cache_path) == -1)
+       {
+         g_printerr ("Could not rename %s to %s: %s, removing %s then.\n",
+                     cache_path, bak_cache_path,
+                     g_strerror (errno),
+                     cache_path);
+         g_unlink (cache_path);
+         bak_cache_path = NULL;
+       }
+    }
+#endif
+
   if (g_rename (tmp_cache_path, cache_path) == -1)
     {
+      g_printerr ("Could not rename %s to %s: %s\n",
+                 tmp_cache_path, cache_path,
+                 g_strerror (errno));
       g_unlink (tmp_cache_path);
+#ifdef G_OS_WIN32
+      if (bak_cache_path != NULL)
+       if (g_rename (bak_cache_path, cache_path) == -1)
+         g_printerr ("Could not rename %s back to %s: %s.\n",
+                     bak_cache_path, cache_path,
+                     g_strerror (errno));
+#endif
       exit (1);
     }
+#ifdef G_OS_WIN32
+  if (bak_cache_path != NULL)
+    g_unlink (bak_cache_path);
+#endif
 
   /* Update time */
   /* FIXME: What do do if an error occurs here? */